package gx.web.controller;

import javax.servlet.Servlet;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sun.net.httpserver.HttpServer;

import gx.service.common.CheckCodeService;

//登录验证码
@Controller
public class CheckCodeController {
@Autowired
private CheckCodeService checkCodeService;
@RequestMapping("/yzm.jhtml")
public void execute(HttpServletResponse response,HttpSession session) throws Exception{
	//获取验证码
	String code =checkCodeService.randomString(4);
	
	session.setAttribute("real_code", code);
	response.setContentType("img/png");
	//为了防止客户缓存图片，禁用客户端缓存
	response.addHeader("pragma", "no-cache");
	response.addHeader("cache-control", "no-cache");
	response.addHeader("expires", "0");
	ServletOutputStream out=response.getOutputStream();
	checkCodeService.renderImage(code, out, 85, 34);
}

}
